package org.neframework.webtest.action.user.user;

import java.util.List;
import java.util.Map;

import org.neframework.webtest.model.t_fk_user;
import org.neframework.webtest.service.UserService;

import org.neframework.webtest.base.BaseController;
import com.tmsps.neframework.core.utils.JsonTools;
import com.tmsps.neframework.mvc.annotation.Controller;
import com.tmsps.neframework.mvc.annotation.RequestMapping;
import com.tmsps.neframework.mvc.annotation.ResponseBody;
import com.tmsps.neframework.mvc.plugin.Tip;

@Controller
@RequestMapping("/cp/user/user")
public class UserController extends BaseController {

	private static final UserService userService = new UserService();

	@RequestMapping("/list")
	public String list() {
		return "/jsp/user/user/list.jsp";
	}

	@RequestMapping("/list_data")
	@ResponseBody
	public void list_data(String srh_uname) {

		List<Map<String, Object>> list = userService.selectUserList(srh_uname, sort_params, page);

		result.put("list", list);
	}

	@RequestMapping("/add")
	@ResponseBody
	public void add(t_fk_user user) {
		user.setType("普通用户");
		oc.saveObj(user);

		this.setTipMsg(true, "保存成功!", Tip.Type.success);
	}

	@RequestMapping("/edit_form")
	@ResponseBody
	public String edit_form(String kid) {
		t_fk_user user = (t_fk_user) oc.findObjById(kid, t_fk_user.class);
		return JsonTools.toJson("user", user);
	}

	@RequestMapping("/edit")
	@ResponseBody
	public void edit(t_fk_user user) {
		t_fk_user userDb = (t_fk_user) oc.findObjById(user.getKid(), t_fk_user.class);
		userDb.setUname(user.getUname());
		userDb.setName(user.getName());
		userDb.setSex(user.getSex());
		oc.updateObj(userDb);

		this.setTipMsg(true, "保存成功!", Tip.Type.success);
	}

	@RequestMapping("/del")
	@ResponseBody
	public void del(String kid) {
		oc.delObjById(kid, t_fk_user.class);

		this.setTipMsg(true, "删除成功!", Tip.Type.success);
	}

}
